package lpg;

class Tab
{
    static int tabSize()
    {
        return tabSize;
    }

    static void setTabSize(int value)
    {
        tabSize = value;
    }

    //
    // Compute the length of a character string segment after expanding tabs.
    //
    static int strlen(char[] line, int start, int end)
    {
        for (int i = start--; i <= end; i++)
        {
            if (line[i] == HORIZONTAL_TAB)
            {
                int offset = (i - start) - 1;
                start -= ((tabSize - 1) - offset % tabSize);
            }
        }

        return (end - start);
    }

    static final char HORIZONTAL_TAB    = '\t';
    static final int DEFAULT_TAB_SIZE   = 8;
    private static int tabSize          = DEFAULT_TAB_SIZE;

    private Tab()
    {
    }

}
